home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 3.9 KB | 142 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLbInit.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #if defined(SYMANTEC_CPLUS) && defined(FW_BUILD_MAC)
- #define ODFCFMINIT PartCFMInit
- #endif
-
- //========================================================================================
- // Prototypes
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- extern "C" pascal OSErr ODFCFMINIT (CFragInitBlockPtr initBlkPtr);
- extern "C" pascal void ODFCFMTERM (void);
-
- #ifdef __MWERKS__
- # if __MWERKS__ < 0x0800
- extern "C" void __sinit();
- extern "C" void __destroy_global_chain(void);
- # else
- extern "C" short __initialize();
- extern "C" void __terminate(void);
- # endif
- #elif defined __MRC__
- extern "C" __init_lib(CFragInitBlockPtr initBlkPtr);
- #endif
-
- #endif // FW_BUILD_MAC
-
- //========================================================================================
- // Global Variable
- //========================================================================================
- // FW_gInstance is initialized in DLLMain for Windows
- // FW_gInstance is defined in FWCFMRes.cpp for the Mac
- #ifdef FW_BUILD_WIN
- FW_Instance FW_gInstance = NULL;
- #endif
-
- //========================================================================================
- // Initialization methods
- //========================================================================================
-
- #ifdef FW_BUILD_WIN32
- //----------------------------------------------------------------------------------------
- // DllMain
- //----------------------------------------------------------------------------------------
- extern "C" BOOL WINAPI DllMain(HINSTANCE hDLL,
- DWORD dwReason,
- LPVOID /* lpReserved */)
- {
- if(dwReason == DLL_PROCESS_ATTACH)
- {
- // Save instance handle for future use
- FW_gInstance = hDLL;
- }
-
- return TRUE;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // ODFCFMINIT (Has to be upper case because of the 68K Linker)
- //----------------------------------------------------------------------------------------
-
- extern "C" pascal OSErr ODFCFMINIT(CFragInitBlockPtr initBlkPtr)
- {
- #ifdef FW_DEBUG
- #define FW_COMMAND 0x37
-
- KeyMap theKeyMap;
- ::GetKeys(theKeyMap);
- const unsigned char *theKeys = (const unsigned char *) theKeyMap;
- if ((theKeys[FW_COMMAND >> 3] >> (FW_COMMAND & 7)) & 1)
- ::DebugStr("\pODFCFMInit");
- #endif
-
- // Shared libraries don't get there static objects initialized correctly without
- // calling __initialize or __CPlusInit for MetroWerks or MrC respectively.
- #ifdef __MWERKS__
- #if __MWERKS__ < 0x0800
- __sinit();
- #else
- __initialize();
- #endif
- #elif defined __MRC__
- __init_lib(initBlkPtr);
- #endif
-
- #ifndef FW_NATIVE_EXCEPTIONS
- // FW_gInStaticInit is initialized to a special magic number before static initialization (at linktime)
- // within SLExcept.cpp. Here we clear it to zero. This allows FWExcLib to
- // understand when static objects are being constructed.
- extern long FW_gInStaticInit;
- FW_gInStaticInit = 0L;
- #endif
-
- OSErr err1 = ::InitODMemory();
-
- OSErr err2 = FW_CAcquireCFMResourceAccess::PrivInitLibraryResources(initBlkPtr);
-
- return (OSErr)(err1 != noErr) ? err1 : err2;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // ODFCFMTERM
- //----------------------------------------------------------------------------------------
-
- extern "C" pascal void ODFCFMTERM(void)
- {
- FW_CAcquireCFMResourceAccess::PrivCloseLibraryResources();
-
- #ifdef __MWERKS__
- # if __MWERKS__ < 0x0800
- __destroy_global_chain();
- # else
- __terminate();
- # endif
- #endif
-
- }
- #endif
-
-